package com.juneyao.bigdata.controller;


import com.juneyao.bigdata.domain.Activity;
import com.juneyao.bigdata.domain.PeopleGroupId;
import com.juneyao.bigdata.domain.ResultFlag;
import com.juneyao.bigdata.service.ActionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author quanbiao
 * @date 2018-06-28
 * 活动controller
 */
@RequestMapping("/action")
@RestController
public class ActionController {

    private Logger logger = LoggerFactory.getLogger("ActionController");

    @Autowired
    private ActionService actionService;

    /**
     * 活动确认发送
     * @param activity
     * @return
     */
    @RequestMapping(value = "confirm",method = {RequestMethod.GET, RequestMethod.POST})
    public ResultFlag actionConfirm(@RequestBody Activity activity){
        logger.info("logger starting....");
        logger.info("activity="+activity.toString());
        ResultFlag res = this.actionService.activitySend(activity);

        logger.info("json_str="+res.toString());
        return res;
    }

    /**
     * 产品使用量
     * @param peopleGroupId
     * @return
     */
    @RequestMapping(value = "productused",method = {RequestMethod.GET, RequestMethod.POST})
    public String productUsedsum(@RequestBody PeopleGroupId peopleGroupId){
        logger.info("logger starting....");
        List<Activity> activity_list = actionService.getActivityUsed(peopleGroupId);
        logger.info("产品使用量 结果返回JsArr1="+activity_list.toString());
        return "{ \"data\":" + activity_list.toString() + ",\"msg\":\"OK\",\"status\":\"200\"}";

    }

}
